package graph.day06;

import java.util.Scanner;

public class Kama_106 {

    static int[][] graph;

    static int[][] direction = {{-1, 0}, {1, 0}, {0, 1}, {0, -1}};


    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        graph = new int[n][m];
        int count = 0;
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                graph[i][j] = sc.nextInt();
                if (graph[i][j] == 1) count++;
            }
        }
        int res = count * 4;
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                if (graph[i][j] == 1) {
                    for (int[] dir : direction) {
                        int nextX = i + dir[0];
                        int nextY = j + dir[1];
                        if (nextX < 0 || nextY < 0 || nextX >= graph.length || nextY >= graph[0].length) continue;
                        if (graph[nextX][nextY] == 1) res--;
                    }
                }
            }
        }
        System.out.println(res);
    }
}
